/*
 * Edit_Department.java
 *
 * Created on July 28, 2008, 9:02 PM
 */

package schedule_master;
import javax.swing.JFrame;
import java.sql.*;
import java.util.ArrayList;
import javax.swing.JList;
import javax.swing.DefaultListModel;
import java.awt.Cursor;

/**
 *
 * @author  PGSIST
 */
public class Edit_Department extends javax.swing.JPanel {
    DefaultListModel model = new DefaultListModel();
    DefaultListModel modelTeachers = new DefaultListModel();
    DefaultListModel modelClass = new DefaultListModel();
    Schedule_MasterView smv;
    /** Creates new form Edit_Department */
    public Edit_Department(Schedule_MasterView smv1) {
        initComponents();
        jPanel1.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
        smv=smv1;
    }
    public JList getDepartmentList(){
       ArrayList<String> departments = new ArrayList<String>();
       
       // departments.add("Department");
        // Try to access the database, otherwise, catch the exception
        try{
            String driver = "com.mysql.jdbc.Driver";
            Class.forName(driver);
        
            String url = "jdbc:mysql://pgsist.org:3306/2008_itp0";
            String userNameSQL = "itp0";
            String passwordSQL = "frebre3w";
            String deptIDQuery = "Select deptID " +
                                 "FROM tblDepartments " +
                                 "WHERE true";
            String deptNameQuery = "Select deptName " +
                               "FROM tblDepartments " +
                               "WHERE 1";
            
            
            System.out.println("Connecting to database...");
            Connection conn = DriverManager.getConnection(url, userNameSQL, passwordSQL);
            System.out.println("Done.");
        
            Statement st = conn.createStatement();
            
            ResultSet res = st.executeQuery(deptIDQuery);
            
            // Count the number of departments
            int i = 0;
            
            // While there is an item in deptID column of tblDepartments
            while(res.next()){
                // Add the current deptID to department array of current index
                departments.add( res.getString(1));
                // Increment the index of the array
                i++;
            } 
            
            // Set i back to zero
            i = 0;
            res = st.executeQuery(deptNameQuery);
            
            // While there is an item in deptName column of tblDepartments
            while(res.next()){
                // Concatenate the current deptName to department array of current index
                
                departments.set(i, departments.get(i) + " " + res.getString(1));
                
                // Increment the index of the array
                i++;
            }
            for (int a=0;a<departments.size();a++)
                model.add(a, departments.get(a));
            
            return new JList(model);
        } catch (Exception e){
            System.err.println(e);
        }
        return new JList();
    }
public JList getTeacherList(String dept){
       ArrayList<String> teachers = new ArrayList<String>();
       
       // departments.add("Department");
        // Try to access the database, otherwise, catch the exception
        try{
            String driver = "com.mysql.jdbc.Driver";
            Class.forName(driver);
        
            String url = "jdbc:mysql://pgsist.org:3306/2008_itp0";
            String userNameSQL = "itp0";
            String passwordSQL = "frebre3w";
            String teacherIDQuery = "Select teacherID " +
                                 "FROM tblTeachers " +
                                 "WHERE deptID=" + dept;
            String teacherNameQuery = "Select lastName " +
                               "FROM tblTeachers " +
                               "WHERE deptID=" + dept;
            
            
            System.out.println("Connecting to database...");
            Connection conn = DriverManager.getConnection(url, userNameSQL, passwordSQL);
            System.out.println("Done.");
        
            Statement st = conn.createStatement();
            
            ResultSet res = st.executeQuery(teacherIDQuery);
            
            // Count the number of departments
            int i = 0;
            
            // While there is an item in deptID column of tblDepartments
            while(res.next()){
                // Add the current deptID to department array of current index
                teachers.add( res.getString(1));
                // Increment the index of the array
                i++;
            } 
            
            // Set i back to zero
            i = 0;
            res = st.executeQuery(teacherNameQuery);
            
            // While there is an item in deptName column of tblDepartments
            while(res.next()){
                // Concatenate the current deptName to department array of current index
                
                teachers.set(i, teachers.get(i) + " " + res.getString(1));
                
                // Increment the index of the array
                i++;
            }
            modelTeachers.clear();
            for (int a=0;a<teachers.size();a++)
                modelTeachers.add(a, teachers.get(a));
            
            return new JList(modelTeachers);
        } catch (Exception e){
            System.err.println(e);
        }
        return new JList();
    }
public JList getClassList(String dept){
       ArrayList<String> classes = new ArrayList<String>();
       
       // departments.add("Department");
        // Try to access the database, otherwise, catch the exception
        try{
            String driver = "com.mysql.jdbc.Driver";
            Class.forName(driver);
        
            String url = "jdbc:mysql://pgsist.org:3306/2008_itp0";
            String userNameSQL = "itp0";
            String passwordSQL = "frebre3w";
            String teacherIDQuery = "Select courseID " +
                                 "FROM tblCourses " +
                                 "WHERE deptID=" + dept;
            String teacherNameQuery = "Select courseName " +
                               "FROM tblCourses " +
                               "WHERE deptID=" + dept;
            
            
            System.out.println("Connecting to database...");
            Connection conn = DriverManager.getConnection(url, userNameSQL, passwordSQL);
            System.out.println("Done.");
        
            Statement st = conn.createStatement();
            
            ResultSet res = st.executeQuery(teacherIDQuery);
            
            // Count the number of departments
            int i = 0;
            
            // While there is an item in deptID column of tblDepartments
            while(res.next()){
                // Add the current deptID to department array of current index
                classes.add( res.getString(1));
                // Increment the index of the array
                i++;
            } 
            
            // Set i back to zero
            i = 0;
            res = st.executeQuery(teacherNameQuery);
            
            // While there is an item in deptName column of tblDepartments
            while(res.next()){
                // Concatenate the current deptName to department array of current index
                
                classes.set(i, classes.get(i) + " " + res.getString(1));
                
                // Increment the index of the array
                i++;
            }
            modelClass.clear();
            for (int a=0;a<classes.size();a++)
                modelClass.add(a, classes.get(a));
            
            return new JList(modelClass);
        } catch (Exception e){
            System.err.println(e);
        }
        return new JList();
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        HomeButton = new javax.swing.JButton();
        LogoutButton = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        DepartmentList = getDepartmentList();
        jScrollPane3 = new javax.swing.JScrollPane();
        TeacherList = getTeacherList("1");
        jLabel3 = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        ClassList = getClassList("1");
        jLabel4 = new javax.swing.JLabel();
        AddDepartmentTextField = new javax.swing.JTextField();
        AddDepartmentButton = new javax.swing.JButton();
        AddTeacherTextField = new javax.swing.JTextField();
        AddTeacherButton = new javax.swing.JButton();
        AddClassTextField = new javax.swing.JTextField();
        AddClassButton = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        DeleteButton = new javax.swing.JButton();
        EditScheduleButton = new javax.swing.JButton();
        SaveButton = new javax.swing.JButton();

        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(schedule_master.Schedule_MasterApp.class).getContext().getResourceMap(Edit_Department.class);
        jPanel1.setBackground(resourceMap.getColor("jPanel1.background")); // NOI18N
        jPanel1.setName("jPanel1"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jPanel5.setBackground(resourceMap.getColor("jPanel5.background")); // NOI18N
        jPanel5.setMaximumSize(new java.awt.Dimension(955, 600));
        jPanel5.setName("jPanel5"); // NOI18N

        jLabel7.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        jLabel7.setName("jLabel7"); // NOI18N

        jLabel2.setIcon(resourceMap.getIcon("jLabel2.icon")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        HomeButton.setText(resourceMap.getString("HomeButton.text")); // NOI18N
        HomeButton.setName("HomeButton"); // NOI18N
        HomeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                HomeButtonActionPerformed(evt);
            }
        });

        LogoutButton.setText(resourceMap.getString("LogoutButton.text")); // NOI18N
        LogoutButton.setName("LogoutButton"); // NOI18N
        LogoutButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                LogoutButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 551, Short.MAX_VALUE)
                        .addComponent(HomeButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(LogoutButton)
                        .addGap(310, 310, 310))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addContainerGap(1345, Short.MAX_VALUE))))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(LogoutButton)
                        .addComponent(HomeButton))
                    .addComponent(jLabel2)
                    .addComponent(jLabel7))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        DepartmentList.setDragEnabled(true);
        DepartmentList.setName("DepartmentList"); // NOI18N
        DepartmentList.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                DepartmentListMouseEntered(evt);
            }
        });
        DepartmentList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                DepartmentListValueChanged(evt);
            }
        });
        jScrollPane2.setViewportView(DepartmentList);

        jScrollPane3.setName("jScrollPane3"); // NOI18N

        TeacherList.setName("TeacherList"); // NOI18N
        TeacherList.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                TeacherListMouseEntered(evt);
            }
        });
        jScrollPane3.setViewportView(TeacherList);

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jScrollPane4.setName("jScrollPane4"); // NOI18N

        ClassList.setName("ClassList"); // NOI18N
        ClassList.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                ClassListMouseEntered(evt);
            }
        });
        jScrollPane4.setViewportView(ClassList);

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        AddDepartmentTextField.setText(resourceMap.getString("AddDepartmentTextField.text")); // NOI18N
        AddDepartmentTextField.setName("AddDepartmentTextField"); // NOI18N
        AddDepartmentTextField.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                AddDepartmentTextFieldMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                AddDepartmentTextFieldMouseExited(evt);
            }
        });
        AddDepartmentTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AddDepartmentTextFieldActionPerformed(evt);
            }
        });

        AddDepartmentButton.setText(resourceMap.getString("AddDepartmentButton.text")); // NOI18N
        AddDepartmentButton.setEnabled(false);
        AddDepartmentButton.setName("AddDepartmentButton"); // NOI18N
        AddDepartmentButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AddDepartmentButtonActionPerformed(evt);
            }
        });

        AddTeacherTextField.setText(resourceMap.getString("AddTeacherTextField.text")); // NOI18N
        AddTeacherTextField.setName("AddTeacherTextField"); // NOI18N
        AddTeacherTextField.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                AddTeacherTextFieldMouseEntered(evt);
            }
        });
        AddTeacherTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AddTeacherTextFieldActionPerformed(evt);
            }
        });
        AddTeacherTextField.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
                AddTeacherTextFieldCaretPositionChanged(evt);
            }
            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
            }
        });

        AddTeacherButton.setText(resourceMap.getString("AddTeacherButton.text")); // NOI18N
        AddTeacherButton.setEnabled(false);
        AddTeacherButton.setName("AddTeacherButton"); // NOI18N
        AddTeacherButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AddTeacherButtonActionPerformed(evt);
            }
        });

        AddClassTextField.setText(resourceMap.getString("AddClassTextField.text")); // NOI18N
        AddClassTextField.setName("AddClassTextField"); // NOI18N
        AddClassTextField.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                AddClassTextFieldMouseEntered(evt);
            }
        });
        AddClassTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AddClassTextFieldActionPerformed(evt);
            }
        });

        AddClassButton.setText(resourceMap.getString("AddClassButton.text")); // NOI18N
        AddClassButton.setEnabled(false);
        AddClassButton.setName("AddClassButton"); // NOI18N
        AddClassButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AddClassButtonActionPerformed(evt);
            }
        });

        jButton6.setText(resourceMap.getString("jButton6.text")); // NOI18N
        jButton6.setName("jButton6"); // NOI18N

        DeleteButton.setText(resourceMap.getString("DeleteButton.text")); // NOI18N
        DeleteButton.setName("DeleteButton"); // NOI18N
        DeleteButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DeleteButtonActionPerformed(evt);
            }
        });

        EditScheduleButton.setText(resourceMap.getString("EditScheduleButton.text")); // NOI18N
        EditScheduleButton.setName("EditScheduleButton"); // NOI18N
        EditScheduleButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                EditScheduleButtonActionPerformed(evt);
            }
        });

        SaveButton.setText(resourceMap.getString("SaveButton.text")); // NOI18N
        SaveButton.setName("SaveButton"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(44, 44, 44)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(AddDepartmentTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(AddDepartmentButton))
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(jLabel1)
                                    .addGap(36, 36, 36))
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 166, Short.MAX_VALUE))
                            .addComponent(SaveButton)
                            .addComponent(EditScheduleButton))
                        .addGap(20, 20, 20)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jScrollPane3)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(AddTeacherTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(AddTeacherButton)))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(1, 1, 1)
                                .addComponent(jLabel3)))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel4)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(jScrollPane4)
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                        .addComponent(AddClassTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(AddClassButton)))
                                .addGap(34, 34, 34)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jButton6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(DeleteButton))))
                        .addGap(752, 752, 752)))
                .addGap(268, 268, 268))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(AddDepartmentTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(AddDepartmentButton)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(AddTeacherTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(AddTeacherButton)))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(AddClassTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(AddClassButton)))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(62, 62, 62)
                        .addComponent(jButton6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(DeleteButton)))
                .addGap(18, 18, 18)
                .addComponent(SaveButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(EditScheduleButton)
                .addContainerGap(386, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

private void HomeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_HomeButtonActionPerformed
JFrame frame= new JFrame("Welcome Some more");
  frame.add( new HomePage(smv));
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   frame.setVisible(true);
frame.pack();
kill();
}//GEN-LAST:event_HomeButtonActionPerformed

private void AddDepartmentTextFieldMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_AddDepartmentTextFieldMouseEntered
// TODO add your handling code here:
    if (!AddDepartmentButton.isEnabled()){
    AddDepartmentTextField.setText("");
    AddDepartmentButton.setEnabled(true);
    // DepartmentList.setEnabled(true);
    AddTeacherTextField.setText("Add Teacher...");
    AddTeacherButton.setEnabled(false);
    // TeacherList.setEnabled(false);
    AddClassTextField.setText("Add Class...");
    AddClassButton.setEnabled(false);
   // ClassList.setEnabled(false);
    }
}//GEN-LAST:event_AddDepartmentTextFieldMouseEntered

private void AddTeacherTextFieldMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_AddTeacherTextFieldMouseEntered
// TODO add your handling code here:
    if (!AddTeacherButton.isEnabled()){
     AddTeacherTextField.setText("");
    AddTeacherButton.setEnabled(true);
     //TeacherList.setEnabled(true);
    AddDepartmentTextField.setText("Add Department...");
    AddDepartmentButton.setEnabled(false);
    //DepartmentList.setEnabled(false);
    AddClassTextField.setText("Add Class...");
    AddClassButton.setEnabled(false);
    //ClassList.setEnabled(false);
   
    }
}//GEN-LAST:event_AddTeacherTextFieldMouseEntered

private void AddClassTextFieldMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_AddClassTextFieldMouseEntered
// TODO add your handling code here:ClassList.setEnabled(true);
    if (!AddClassButton.isEnabled()){
    AddClassTextField.setText("");
    AddClassButton.setEnabled(true);
    //ClassList.setEnabled(true);
    AddDepartmentTextField.setText("Add Department...");
    AddDepartmentButton.setEnabled(false);
    //DepartmentList.setEnabled(false);
    AddTeacherTextField.setText("Add Teacher...");
    AddTeacherButton.setEnabled(false);
    //TeacherList.setEnabled(false);
    }
}//GEN-LAST:event_AddClassTextFieldMouseEntered

private void AddDepartmentTextFieldMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_AddDepartmentTextFieldMouseExited
// TODO add your handling code here:
}//GEN-LAST:event_AddDepartmentTextFieldMouseExited

private void AddTeacherTextFieldCaretPositionChanged(java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_AddTeacherTextFieldCaretPositionChanged
// TODO add your handling code here:
}//GEN-LAST:event_AddTeacherTextFieldCaretPositionChanged

private void AddDepartmentButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AddDepartmentButtonActionPerformed
// TODO add your handling code here:
    String s="";
    DepartmentList.setSelectedIndex(DepartmentList.getModel().getSize()-1);
    try{
    s+=  (Integer.parseInt(DepartmentList.getSelectedValue().toString().substring(0, 2))+1);
    }
    catch(java.lang.NumberFormatException nfe){
        s+=  (Integer.parseInt(DepartmentList.getSelectedValue().toString().substring(0, 1))+1);
    
    }
    s+=" "+AddDepartmentTextField.getText();
    model.add(DepartmentList.getModel().getSize(),s);
}//GEN-LAST:event_AddDepartmentButtonActionPerformed

private void AddTeacherButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AddTeacherButtonActionPerformed
// TODO add your handling code here:
    
}//GEN-LAST:event_AddTeacherButtonActionPerformed

private void AddClassButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AddClassButtonActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_AddClassButtonActionPerformed

private void AddDepartmentTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AddDepartmentTextFieldActionPerformed
AddDepartmentButtonActionPerformed(evt);// TODO add your handling code here:
}//GEN-LAST:event_AddDepartmentTextFieldActionPerformed

private void AddTeacherTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AddTeacherTextFieldActionPerformed
// TODO add your handling code here:
    AddTeacherButtonActionPerformed(evt);
}//GEN-LAST:event_AddTeacherTextFieldActionPerformed

private void AddClassTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AddClassTextFieldActionPerformed
// TODO add your handling code here:
    AddClassButtonActionPerformed(evt);
}//GEN-LAST:event_AddClassTextFieldActionPerformed

private void LogoutButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_LogoutButtonActionPerformed
// TODO add your handling code here:
   smv.getFrame().setVisible(true);
    // Schedule_MasterApp.getApplication().show(new Schedule_MasterView(Schedule_MasterApp.getApplication()));
    kill();
}//GEN-LAST:event_LogoutButtonActionPerformed

private void DeleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DeleteButtonActionPerformed
// TODO add your handling code here:
    if (DepartmentList.getSelectedIndex()>-1&&DepartmentList.getMaxSelectionIndex()>0){
        model.remove(DepartmentList.getSelectedIndex());
       DepartmentListValueChanged();
    }
}//GEN-LAST:event_DeleteButtonActionPerformed

private void DepartmentListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_DepartmentListValueChanged
// TODO add your handling code here:
   DepartmentListValueChanged();
}//GEN-LAST:event_DepartmentListValueChanged

private void TeacherListMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_TeacherListMouseEntered
AddTeacherTextFieldMouseEntered(evt);
    // TODO add your handling code here:
}//GEN-LAST:event_TeacherListMouseEntered

private void DepartmentListMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_DepartmentListMouseEntered
AddDepartmentTextFieldMouseEntered(evt);
    // TODO add your handling code here:
}//GEN-LAST:event_DepartmentListMouseEntered

private void ClassListMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ClassListMouseEntered
// TODO add your handling code here:
    AddClassTextFieldMouseEntered(evt);
}//GEN-LAST:event_ClassListMouseEntered

private void EditScheduleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EditScheduleButtonActionPerformed
// TODO add your handling code here:
    JFrame frame= new JFrame("I want to edit some schedules. Let's do it!!!");
  frame.add( new Edit_Schedule(smv));
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   frame.setVisible(true);
frame.pack();
    
    kill();
}//GEN-LAST:event_EditScheduleButtonActionPerformed
private void DepartmentListValueChanged() {
// TODO add your handling code here:
    String s="";
    
    try{
    s+=  (Integer.parseInt(DepartmentList.getSelectedValue().toString().substring(0, 2)));
    }
    catch(java.lang.NumberFormatException nfe){
        s+=  (Integer.parseInt(DepartmentList.getSelectedValue().toString().substring(0, 1)));
    
    }
    catch(java.lang.NullPointerException npe){
        DepartmentList.setSelectedIndex(0);
        try{
            s+=  (Integer.parseInt(DepartmentList.getSelectedValue().toString().substring(0, 2)));
            }
            catch(java.lang.NumberFormatException nfe){
             s+=  (Integer.parseInt(DepartmentList.getSelectedValue().toString().substring(0, 1)));
    
            }
    }
    TeacherList=getTeacherList(s);
    ClassList= getClassList(s);
}
private void kill(){
    
     ( (JFrame)(this.getTopLevelAncestor())).dispose();
    
}

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton AddClassButton;
    private javax.swing.JTextField AddClassTextField;
    private javax.swing.JButton AddDepartmentButton;
    private javax.swing.JTextField AddDepartmentTextField;
    private javax.swing.JButton AddTeacherButton;
    private javax.swing.JTextField AddTeacherTextField;
    private javax.swing.JList ClassList;
    private javax.swing.JButton DeleteButton;
    private javax.swing.JList DepartmentList;
    private javax.swing.JButton EditScheduleButton;
    private javax.swing.JButton HomeButton;
    private javax.swing.JButton LogoutButton;
    private javax.swing.JButton SaveButton;
    private javax.swing.JList TeacherList;
    private javax.swing.JButton jButton6;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    // End of variables declaration//GEN-END:variables

}
